﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Cstudy.DAL
{
    public class resources
    {
        public bool AddRescources(MODEL.resources rescource)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@title",rescource.Title),
                new SqlParameter("@content",rescource.Content),
                new SqlParameter("@authorid",rescource.AuthorID),
                new SqlParameter("@classid",rescource.ClassID)
            };
            return COM.SQLHelper.ExecuteNonQuery("ss_AddRescources", parms);
        }

        public bool DeleteRescource(int resid)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@resid",resid)
            };
            return COM.SQLHelper.ExecuteNonQuery("@sp_DeleteRescources", parms);
        }

        public bool UpdateRescoures(MODEL.resources rescource)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@resid",rescource.ResID),
                new SqlParameter("@title",rescource.Title),
                new SqlParameter("@content",rescource.Content),
                new SqlParameter("@classid",rescource.ClassID)
            };
            return COM.SQLHelper.ExecuteNonQuery("ss_UpdateRescources", parms);
        }

        public DataSet SearchRescources(string keyword)
        {
            keyword = "%" + keyword.Replace(" ", "%") + "%";
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@keyword",keyword)
            };
            return COM.SQLHelper.ExecuteQuery("sp_SearchRescources",parms);
        }

        public DataSet SelectResources()
        {
            return COM.SQLHelper.ExecuteQuery("@sp_SelectResources");
        }

        public DataSet SelectResourcesByClassID(int classid)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@classid",classid)
            };
            return COM.SQLHelper.ExecuteQuery("@sp_SelectResourcesByClassID", parms);
        }

    }
}
